package cn.itsource.pethome.pet.controller;

import cn.itsource.pethome.pet.domain.PetType;
import cn.itsource.pethome.pet.service.IPetTypeService;
import cn.itsource.pethome.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/petType")
public class PetTypeController {

    @Autowired
    private IPetTypeService petTypeService;

    @PutMapping
    public AjaxResult saveOrUpdate(@RequestBody PetType petTypeType){
        if (petTypeType.getId() == null){
            petTypeService.save(petTypeType);
        }else {
            petTypeService.update(petTypeType);
        }
        return AjaxResult.me();
    }

    @DeleteMapping(value = "/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        petTypeService.delete(id);
        return AjaxResult.me();
    }

    @GetMapping(value = "/{id}")
    public PetType selectById(@PathVariable("id") Long id){
        return petTypeService.loadById(id);
    }

    @GetMapping
    public List<PetType> seleceAll(){
        return petTypeService.loadAll();
    }



}
